<template>
	<view class="store">
		<view class="nav">
			<view class="item" @click="batchFun('category')">
				<image src="http://app.chinasrv.com/attachment/xcx/icon/icon4.png" mode="aspectFill" ></image>
				<text style="font-size: 40rpx;">商品分类</text>
			</view>
			<view class="item" @click="batchFun('brand')">
				<image src="http://app.chinasrv.com/attachment/xcx/icon/icon5.png" mode="aspectFill" ></image>
				<text style="font-size: 40rpx;">商品品牌</text>
			</view>
		</view>
		<view class="nav1">
			<image src="../static/img/tab_alcohol.png" lazy-load="true" mode="aspectFill" @click="batchFun('brand', 'type=1')"></image>
			<image src="../static/img/tab_tea.png" lazy-load="true" mode="aspectFill" @click="batchFun('brand', 'type=2')"></image>
		</view>
		<view class="content1" v-for="(tabItem, k) in tabList" :key="k">
			<view class="title">
				{{tabItem.title}}
			</view>
			<view class="list">
				<view class="list_item" v-for="(item,index) in tabItem.productList" :key="index" @click="batchFun('detail', 'id='+item.id)">
					<image :src="item.picture" mode=""></image>
                    
					<view class="item_text">
                        <text class="state" style="background:rgba(235, 89, 56, 1);">{{item.reductionName}}</text>
                        {{item.name}}
                    </view>
					<view class="item_text1">
						<view>￥{{item.price}}</view>
					</view>
				</view>
			</view>
		</view>
		<movable-view class="xf" direction="all" @click="batchFun('cart')">
			<image src="http://hdsq.aoorange.cn/attachment/xcx/icon/car.png" mode="scaleToFill"></image>
			<text v-if="cartNum > 0">{{cartNum}}</text>
		</movable-view>
		
	</view>
</template>

<script>
	var _self;
	import serve from '../static/request.js';
	import storage from '../static/appkey.js';
	import common from '../static/jump.js';
	export default {
		data() {
			return {
				tabList: {},
				dotsStyles: {
					backgroundColor: 'rgba(255,255,255,0.3)',
					selectedBackgroundColor: '#FFC600',
					selectedBorder: '1px rgba(255,198,0,1) solid',
					border: '1px rgba(255,255,255,0.3) solid',
					selectedBorder: '1px rgba(255,198,0,1) solid'
				}, //轮播图样式配置
			}
		},
		methods: {
			getIndex() {
				serve.request({
					url: '/shop/batch/index',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
					}
				}).then(res => {
					if(res.data.errorType > 0) {
						let rechargeMoney = res.data.wholesaler_money;
						uni.showModal({
							title: '温馨提示',
							content: res.data.errorMessage,
							showCancel:true,
							cancelText: '继续看看',
							confirmText:'去充值',
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url: '/business/recharge?money='+rechargeMoney
									})
								} 
							}
						});
					}
					_self.tabList = res.data.tabList;
				});
			},
			getCartNum() {
				serve.request({
					url: '/shop/batch/cart-num',
					data: {
						appkey: uni.getStorageSync('appkey'),
						'access-token': uni.getStorageSync('access-token'),
					}
				}).then(res => {
					_self.cartNum = res.data.num;
				});
			},
			batchFun(filename, field) {
				uni.navigateTo({
				    url: '/batch/'+filename+'?'+field
				});
			}
		},
		onLoad() {
			_self = this;
		},
		onShow() {
			_self.getIndex();
			_self.getCartNum();
		},
		onPullDownRefresh() {
			_self.getIndex();
		}
	}
</script>

<style lang="scss" scoped>
	@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
		.store {
			padding-bottom: 164rpx !important;
		}
	}
	.store {
		width: 100%;
		padding-bottom: 140rpx;
        .xf{
			position: fixed;
			left: 630rpx;
			top: 70%;
			width:90rpx;
			height:90rpx;
			image{
				width:100%;
				height:100%;
			}
			text{
				position: absolute;
				width: 30rpx;
				height: 30rpx;
				right: 5rpx;
				line-height: 30rpx;
				text-align: center;
				border-radius: 50%;
				font-size: 18rpx;
				background: red;
				color: #FFFFFF;
			}
		}
		.content1 {
			box-sizing: border-box;
			width: 100%;
			padding: 48rpx 30rpx 18rpx;
			border-top: 16rpx #FBFBFD solid;
			border-bottom: 16rpx #FBFBFD solid;
			.title {
				position: relative;
				// width: 130rpx;
				font-size: 40rpx;
				// text-align: center;
				height: 24rpx;
				line-height: 24rpx;
				padding-left: 20rpx;
			}

			.title::before {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 6rpx;
				height: 24rpx;
				background: rgba(255, 198, 0, 1);
				border-radius: 2rpx;
			}

			.list {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				padding: 30rpx 0rpx 0rpx;
				.list_item {
					width: 330rpx;
					padding-bottom: 30rpx;
					image {
						width: 330rpx;
						height: 340rpx;
						border-radius: 3%;
					}
                    .state{
                        padding: 5rpx 8rpx;
                        text-align: center;
                        color: #FFFFFF;
                        font-size: 32rpx;
                        border-radius:2rpx;
                        margin-right: 10rpx;
                    }
					.item_text{
						margin-top: 30rpx;
						font-size:32rpx;
						font-weight:bold;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
                        
					}
					.item_text1{
						view:nth-child(1) {
							color: #FFC600;
							font-size: 32rpx;
						}
						
						view:nth-child(2) {
							color: #CBCBCB;
							font-size: 24rpx;
							text-decoration: line-through;
							margin-left: 8rpx;
						}
					}
				}
			}
		}


		.nav {
			box-sizing: border-box;
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 40rpx 107rpx;
			border-bottom: 16rpx #FBFBFD solid;
			.item {
				display: flex;
				align-items: center;
				font-size: 28rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}
			}
		}
		
		.nav1 {
			box-sizing: border-box;
			padding: 40rpx 30rpx;
			display: flex;
			justify-content: space-between;
			border-bottom: 16rpx #FBFBFD solid;
			
			image {
				width: 330rpx;
				height: 130rpx;
				border-radius: 10rpx;
			}
		}
	}
</style>
